import TabMenu from './data';
Component({
  data: {
    active: 0,
    list: [],
  },
  attached() {
    // 动态获取数据
    let dynamicData;
    // 修改list数据
    if (wx.getStorageSync('userType') == 0) {
      dynamicData = [
        {
          icon: 'sort',
          text: '预约',
          url: '/pages/goods/category/index',
        },
        {
          icon: 'home',
          text: '预约记录',
          url: '/pages/home/home',
        },
      ];
    } else  {
      dynamicData = [
        {
          icon: 'sort',
          text: '扫码',
          url: '/pages/scanCode/scanCode',
        },
        {
          icon: 'home',
          text: '患者信息',
          url: '/pages/sickList/sickList',
        },
      ];
    }
    this.setData({ list: dynamicData });
  },

  methods: {
    onChange(event) {
      this.setData({ active: event.detail.value });
      console.log(event);
      wx.switchTab({
        url: this.data.list[event.detail.value].url.startsWith('/')
          ? this.data.list[event.detail.value].url
          : `/${this.data.list[event.detail.value].url}`,
      });
    },

    init() {
      const page = getCurrentPages().pop();
      const route = page ? page.route.split('?')[0] : '';
      console.log(route);
      const active = this.data.list.findIndex(
        (item) => (item.url.startsWith('/') ? item.url.substr(1) : item.url) === `${route}`,
      );
      this.setData({ active });
    },
  },
});
